package com.mchsdk.paysdk.http.process;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

import org.apache.http.entity.StringEntity;

import com.lidroid.xutils.http.RequestParams;
import com.mchsdk.open.ApiCallback;
import com.mchsdk.paysdk.bean.ChannelAndGameInfo;
import com.mchsdk.paysdk.bean.PersonalCenterModel;
import com.mchsdk.paysdk.config.MCHConstant;
import com.mchsdk.paysdk.http.request.PTBPayRequest;
import com.mchsdk.paysdk.utils.MCLog;
import com.mchsdk.paysdk.utils.RequestParamUtil;

import android.os.Handler;

public class PTBPayProcess {

	private static final String TAG = "PtbPayProcess";

	/**
	 * 商品名称
	 */
	private String goodsName;

	/**
	 * 商品价格
	 */
	private String goodsPrice;
	/**
	 * 商品描述
	 */
	private String goodsDesc;

	/**
	 * 支付类型 1 非绑定 2绑定
	 */
	private String code;
	/**游戏订单信息*/
	private String extend;
	public void post(Handler handler) {
		Map<String, String> map = new HashMap<String, String>();
		map.put("sdk_version", "0");//表示android发送的请求，固定值0
		map.put("title", goodsName);
		map.put("price", goodsPrice);
		map.put("body", goodsDesc);
		map.put("is_uc",PersonalCenterModel.getInstance().getIs_uc());
//		map.put("game_serverid",ApiCallback.order().getGameServerId());
		map.put("game_id", ChannelAndGameInfo.getInstance().getGameId());
		map.put("game_name", ChannelAndGameInfo.getInstance().getGameName());
		map.put("game_appid", ChannelAndGameInfo.getInstance().getGameAppId());
//		map.put("promote_id", MCHConstant.getInstance().getPromoteId());
//		map.put("promote_account", MCHConstant.getInstance().getPromoteAccount());
		map.put("code", code);
		map.put("extend", extend);
		map.put("is_uc",PersonalCenterModel.getInstance().getIs_uc());
		map.put("account", PersonalCenterModel.getInstance().getAccount());
		map.put("user_id", PersonalCenterModel.getInstance().getUserId());
		
		String param = RequestParamUtil.getRequestParamString(map);
		
		RequestParams params = new RequestParams();
		MCLog.e(TAG, "fun#ptb_pay params:" + map.toString());
		try {
			params.setBodyEntity(new StringEntity(param.toString()));
		} catch (UnsupportedEncodingException e) {
			params = null;
			MCLog.e(TAG, "fun#ptb_pay UnsupportedEncodingException:" + e);
		}

		if (null != handler && null != params) {
			PTBPayRequest ptbPayRequest = new PTBPayRequest(handler);
			ptbPayRequest.post(MCHConstant.getInstance().getPtbPayOrderUrl(), params);
		} else {
			MCLog.e(TAG, "fun#post handler is null or url is null");
		}
	}

	public String getExtend() {
		return extend;
	}

	public void setExtend(String extend) {
		this.extend = extend;
	}

	public void setGoodsName(String goodsName) {
		this.goodsName = goodsName;
	}

	public void setGoodsPrice(String goodsPrice) {
		this.goodsPrice = goodsPrice;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getGoodsDesc() {
		return goodsDesc;
	}

	public void setGoodsDesc(String goodsDesc) {
		this.goodsDesc = goodsDesc;
	}

}
